#pragma once

#include <memory>
#include "Connection.hpp"
#include "Socket.hpp"
#include "Log.hpp"

using namespace LogModule;
using namespace SocketModule;

class Listener : public Connection
{
public:
    Listener(const InetAddr &addr)
        : _addr(addr)
    {
        _listensock = std::make_unique<TCPSocket>(addr, Type::SERVER);
        Connection::SetEvents(EPOLLIN);
        Connection::SetFd(_listensock->Fd());
    }
    void Recver() override
    {
        InetAddr addr;
        int sockfd = _listensock->Accept(&addr);
        if (sockfd < 0)
        {
            LOG(LogLevel::ERROR) << "accept error";
            return;
        }
    }
    void Sender() override
    {
    }
    void Excpeter() override
    {
    }

    ~Listener()
    {
    }

private:
    InetAddr _addr; // 服务器主机地址
    std::unique_ptr<Socket> _listensock;
};